package com.dhecp.project.business.controller;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.dhecp.project.logstics.domain.*;
import com.dhecp.project.storage.domain.GaugeMaintenance;
import com.dhecp.project.storage.mapper.GaugeMaintenanceMapper;
import liquibase.pro.packaged.A;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.DateUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.layui.GridColumnsPropertyModel;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.framework.web.service.BaseInfoSimpleService;
import com.dhecp.project.api.util.ApiConfig;
import com.dhecp.project.business.domain.FbaPlanOrder;
import com.dhecp.project.business.domain.FbaPlanOrderDetail;
import com.dhecp.project.business.domain.FbaProductActive;
import com.dhecp.project.business.domain.FbaShipment;
import com.dhecp.project.business.domain.FbaShipmentDetail;
import com.dhecp.project.business.domain.LogisticsMmodeDetails;
import com.dhecp.project.business.domain.LogisticsMmodeGrads;
import com.dhecp.project.business.domain.ProductActive;
import com.dhecp.project.business.service.FbaPlanOrderService;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.common.domain.ModuleNidAndBid;
import com.dhecp.project.common.service.ModuleNidAndBidService;
import com.dhecp.project.logstics.mapper.LogsticsMmodeDetailsMapper;
import com.dhecp.project.logstics.mapper.LogsticsMmodeGradsMapper;
import com.dhecp.project.logstics.service.FbaBoxDetailService;
import com.dhecp.project.logstics.service.FbaShipmentDetailService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * @program: kjecp
 * @description: 头程计划订单 控制层
 * @author: hlf
 * @create: 2022-08-15 15:13
 */
@Controller
@RequestMapping("/business/fbaplanorder")
public class FbaPlanOrderController extends BaseModuleController {

    private String prefix = "business/fbaplanorder";
    private String moduleTable = ModuleTable.FBA_PLAN_ORDER;
    private String planInventory = ModuleTable.PLANINVENTORY;
    private String moduleTable2 = ModuleTable.FBA_PLAN_ORDER_DETAIL;
    private String moduleTable_ACTIVE = ModuleTable.PRODUCT_ACTIVE;
    private String moduleTable_ZX = ModuleTable.FBA_BOX;
    private String moduleTable_ZXS = ModuleTable.FBA_BOXS;
    private String moduleTable_FH = ModuleTable.FBA_BOXFH;
    private String moduleTable_ZXDL = ModuleTable.FBA_BOX_DETAIL;
    private String moduleTable_FX = ModuleTable.FBA_DISPATCH;
    private String moduleTable_CX = ModuleTable.FBA_DEVANNING;
    private String moduleTable_CXXQ = ModuleTable.FBA_DEVANNING_DETAIL;
    private String moduleTableHJ = ModuleTable.FBA_SHIPMENT;
    private String moduleTableHJD = ModuleTable.FBA_SHIPMENTDETAIL;
    private String moduleTableCl = ModuleTable.FBA_CANCEL;

    @Autowired
    private FbaPlanOrderService fbaPlanOrderService;
    @Autowired
    private ModuleNidAndBidService moduleNidAndBidService;

    @Autowired
    private GridColumnsPropertyModel gridColumnsPropertyModel;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

    @Autowired
    private FbaBoxDetailService fbaBoxDetailService;

    @Autowired
    private BaseInfoSimpleService baseInfoSimpleService;

    @Autowired
    private FbaShipmentDetailService fbaShipmentDetailService;

    @Autowired
    private LogsticsMmodeDetailsMapper logsticsMmodeDetailsMapper;

    @Autowired
    private LogsticsMmodeGradsMapper logsticsMmodeGradsMapper;

    @Autowired
    private GaugeMaintenanceMapper gaugeMaintenanceMapper;

    


    /**
     * @Description: 打开查询列表页
     * @Param: [params]
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @RequiresPermissions("business:fbaplanorder:view")
    @GetMapping()
    public ModelAndView view(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        params.put("entity", new FbaPlanOrder()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("prefix", prefix + "/fbaplanorder"); //页面路径
        params.put("toolBarWidth", 0);
        params.put("checkBox", "yes");

        ModelAndView mv = this.openListPage(params);
        mv.addObject("business", "fbaplanorder");
        mv.addObject("moduleTableZX", moduleTable_ZX);
        mv.addObject("moduleTableHJ", moduleTableHJ);
        mv.addObject("moduleTableFX", moduleTable_FX);
        mv.addObject("detailsName", "详情页");
        mv.addObject("ali1688EcpApiUrl", ApiConfig.getAli1688EcpApiUrl());
        Object importFields = dictionaryForFieldService.queryFieldFrontImport(params); //导入模板字段
        mv.addObject("importFields", importFields);	//导入模板字段
        return mv;
    }


    /**
     *@Description: 根据不同的标签切换不同的列表
     *@Param: [params]
     *@return: org.springframework.web.servlet.ModelAndView
     *@Author: hlf
     *@date: 2022-05-09 11:39
     */
    @GetMapping("/switchover")
    @ResponseBody
    public Map<String, Object> switchover(@RequestParam Map<String, Object> params){
        Map<String, Object> dicFieldsList = new HashMap<String, Object>();
        Object object = null;
        String fixtype = "";
        if (params.get("num").equals("0")){
            params.put("moduleTable", moduleTable);
            params.put("entity", new FbaPlanOrder()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
            fixtype = moduleTable;
        } else  if (params.get("num").equals("1")){
            params.put("moduleTable", moduleTableHJ);
            params.put("entity", new FbaShipment());
            fixtype = moduleTableHJ;
        }else  if (params.get("num").equals("2")){
            params.put("moduleTable", moduleTable_ZX);
            params.put("entity", new FbaBox());
            fixtype = moduleTable_ZX;
//            params.put("moduleTable", moduleTable_FX);
//            params.put("entity", new FbaDispatch());
//            fixtype = moduleTable_FX;
        }else  if (params.get("num").equals("3")){
            params.put("moduleTable", moduleTable_ZXS);
            params.put("entity", new FbaBox());
            fixtype = moduleTable_ZXS;
            //导入批量标记发货模板
            Map<String, Object> params1 = new HashMap<String, Object>();
            params1.put("moduleTable", moduleTable_FH);
            params1.put("entity", new FbaBox());
            object = dictionaryForFieldService.queryFieldFrontImport(params1);
        }else  if (params.get("num").equals("4") || params.get("num").equals("5")){
            params.put("moduleTable", moduleTable_CX);
            params.put("entity", new FbaDevanning());
            fixtype = moduleTable_CX;
        }else  if (params.get("num").equals("6") || params.get("num").equals("7")){
            params.put("moduleTable", moduleTableCl);
            params.put("entity", new FbaCancel());
            fixtype = moduleTableCl;
        }
        params.put("checkBox", "yes");
        params.put("toolBarWidth", 0);
        dicFieldsList=gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
        //返回相对应的查询条件
        dicFieldsList.put("fixtype",baseInfoSimpleService.getFieldFrontConditions(fixtype));
        dicFieldsList.put("userId",ShiroUtils.getUserId());
        //导入模板
        dicFieldsList.put("importFields",dictionaryForFieldService.queryFieldFrontImport(params));
        //导入标记发货模板
        dicFieldsList.put("importFieldFH",object);
        return dicFieldsList;
    }

    /**
     * @Description: 打开制单页
     * @Param: nid 必要参数：单据编码（新增时传默认值 0 ，修改、查看时传单据实际值）
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @RequiresPermissions("business:fbaplanorder:view")
    @GetMapping("/edit")
    public ModelAndView editPage(@RequestParam Map<String, Object> params) {
        if (params.get("nid") == null || params.get("nid") == "") {
            params.put("nid", "0");
        }
        params.put("moduleTable", moduleTable);
        params.put("entity", new FbaPlanOrder()); //用于获取实体属性名取代对应字典字段名，解决大小写敏感问题
        params.put("moduleUrl", prefix); //页面上级路径
        params.put("prefix", prefix + "/fbaplanorder_edit"); //页面路径
        Subject userSubject = ShiroUtils.getSubject();
        int enableEdit = 0;
        boolean vType = false;
        if (params.get(enableEdit) == null || "1".equals(params.get(enableEdit).toString())) {
            if (userSubject.isPermitted("business:fbaplanorder:edit")) { //当前登录用户主体是否有修改的权限
                enableEdit = 1;
            }
        }

        try {
            Map<String, Object> headData = new HashMap<String, Object>();        //表头的业务数据
//          SysModuleSet moduleSet = sysModuleSetService.queryModuleSet(params);//单据设置信息
            FbaPlanOrder businessData = fbaPlanOrderService.queryFirstRecord(params);
            if (businessData == null) { //未查询到对应单据，页面初始化值
                ModuleNidAndBid moduleNidAndBid = moduleNidAndBidService.queryModuleNidAndBidInitial(params);
                businessData = new FbaPlanOrder();

                businessData.setWeightRealPredict(new BigDecimal("0"));
                businessData.setWeightVolPredict(new BigDecimal("0"));
                businessData.setWeightCalPredict(new BigDecimal("0"));
                businessData.setPriceCalPerKg(new BigDecimal("0"));
                businessData.setPriceTranCalWeightPredict(new BigDecimal("0"));
                businessData.setPriceQualityExtra(new BigDecimal("0"));
                businessData.setPriceQualityExtraPerKg(new BigDecimal("0"));
                businessData.setPriceQualityExtraPredict(new BigDecimal("0"));
                businessData.setNumProName(0);
                businessData.setNumProNameBeyond(0);
                businessData.setPriceProNamePerOne(new BigDecimal("0"));
                businessData.setPriceProNameExtraPredict(new BigDecimal("0"));
                businessData.setPriceTranPredict(new BigDecimal("0"));
                businessData.setPriceClearanceOpe(new BigDecimal("0"));
                businessData.setToPurchasePrice(new BigDecimal("0"));
                businessData.setPriceSingleBoxReq(new BigDecimal("0"));
                businessData.setPriceSingleBoxReqZd(new BigDecimal("0"));
                businessData.setNid("0");
                businessData.setCode(moduleNidAndBid.getBid());
                businessData.setCreateTime(new Date());
                businessData.setCid(ShiroUtils.getMandatorCid());
                businessData.setCidName(ShiroUtils.getMandatorCidName());
                businessData.setbUser(ShiroUtils.getMandatorId());
                businessData.setbUserName(ShiroUtils.getMandatorName());
                businessData.setbDept(ShiroUtils.getMandatorDeptPath());
                businessData.setbDeptName(ShiroUtils.getMandatorDeptName());
                businessData.setbPosition(ShiroUtils.getMandatorPositionNameDa());
                businessData.setaUser(ShiroUtils.getUserId());
                businessData.setaUserName(ShiroUtils.getUserName());
                businessData.setaDept(ShiroUtils.getUserDeptPath());
                businessData.setaDeptName(ShiroUtils.getUserDeptName());
                businessData.setaPosition(ShiroUtils.getUserPositionNameDa());
                businessData.setIsDeliver(new Integer(params.get("isDeliver").toString()));
                businessData.setCreationMethod("手动");
                businessData.setAttention3("抛重>实重，预估计重费=MIN(预估计重*计重单价,抛货计重费)；抛重<=实重，预估计重费=预估计重*计重单价；计重单价=梯度计重单价+抛货计重单价");
                headData = TypeUtils.entityToMap(businessData);
            } else {
                businessData.setAttention2("预估物流运费=预估计重费+预估材质附加费+预估品名附加费+预估清关费");
                businessData.setAttention3("抛重>实重，预估计重费=MIN(预估计重*计重单价,抛货计重费)；抛重<=实重，预估计重费=预估计重*计重单价；计重单价=梯度计重单价+抛货计重单价");
                businessData.setAttention6("预估材质附加费=预估计重*材质附加单价");
                businessData.setAttention9("预估品名附加费=超品名数*品名附加费单价");
                businessData.setAttention10("预估清关费=清关费单价*品名占比");
                headData = TypeUtils.entityToMap(businessData);
                vType = businessData.getEffectStock();
            }
            params.put("headData", headData); //表头的业务数据

            params.put("checkBox", "yes"); //生成表格gridColumns时包含复选
            ModelAndView mv = this.openEditPage(params);
            mv.addObject("nowTimeStr", DateUtils.getDate());    //当前日期
            mv.addObject("enableEdit", vType ? 0 : enableEdit); //当前页面是否可编辑（0：不可编辑，1：可编辑）
            if (businessData != null) {
                Map<String, Object> params3 = new HashMap<String, Object>();
                params3.put("code",businessData.getCode());
                params3.put("moduleTable", moduleTable);
                params3.put("orderby", "CodeStockLocation,t1.CommodityCode");
                mv.addObject("List", fbaPlanOrderService.querySonList(params3));//子件数据
            }
            //取商品子件列表网格
            params.put("moduleTable", moduleTable2);
            params.put("entity", new FbaPlanOrderDetail()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
            params.put("readOnly", vType);//生成列是否可编辑
            params.put("toolBarWidth", 0);//操作区
            params.put("checkBox", "yes");
            params.put("getFieldAttributesType", "pageingrid");//pageingrid：网格字段
            mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));

            //获取物流方式详情
            Map<String, Object> params2 = new HashMap<String, Object>();
            params2.put("logisticsMmodeGuid",businessData.getLogisticsMmodeGuid());
            List<LogisticsMmodeDetails> logisticsMmodeDetailsList = logsticsMmodeDetailsMapper.findLogisticsMmodeDetails(params2);
            //获取物流方式梯度
            List<LogisticsMmodeGrads> logisticsMmodeGradList = logsticsMmodeGradsMapper.findLogisticsMmodeGrads(params2);
            List<LogisticsMmodeGrads> logisticsMmodeGrads  = logisticsMmodeGradList.stream().filter(logisticsMmodeGrads1 ->
                    "WLFS".equals(logisticsMmodeGrads1.getType())).collect(Collectors.toList());
            List<LogisticsMmodeGrads> logisticsMmodeInfoItems  = logisticsMmodeGradList.stream().filter(logisticsMmodeGrads1 ->
                    "WLFSTDJZ".equals(logisticsMmodeGrads1.getType())).collect(Collectors.toList());

            params2.remove("logisticsMmodeGuid");
            params2.put("type","WLPMTD");
            //获取品名梯度详情
            List<LogisticsMmodeGrads> wlpmtdList = logsticsMmodeGradsMapper.findLogisticsMmodeGrads(params2);

            mv.addObject("textureList",logisticsMmodeDetailsList);
            mv.addObject("logisticsMmodeGrads",logisticsMmodeGrads);
            mv.addObject("wlpmtdList",wlpmtdList);
            mv.addObject("logisticsMmodeInfoItems",logisticsMmodeInfoItems);
            if (params.get("isDeliver").equals("1")){
                //箱规维护
                mv.addObject("gaugeMaintenanceList",gaugeMaintenanceMapper.select());
            }
            return mv;
        } catch (Exception e) {
            return this.gotoModelAndViewErrorPage(e.getMessage());    //详细信息
        }

    }

    /**
     *@Description: 查询前一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult (data.nid 前一单NID， data.bid 前一单BID)
     *@Author: hlf
     *@date: 2022-05-09 11:40
     */
    @RequiresPermissions("business:fbaplanorder:view")
    @GetMapping("/lastnid")
    @ResponseBody
    public AjaxResult lastNid(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = fbaPlanOrderService.queryLastNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     *@Description: 查询后一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult (data.nid 后一单NID， data.bid 后一单BID)
     *@Author: hlf
     *@date: 2022-05-09 11:40
     */
    @RequiresPermissions("business:fbaplanorder:view")
    @GetMapping("/nextnid")
    @ResponseBody
    public AjaxResult nextNid(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = fbaPlanOrderService.queryNextNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     * @Description: 查询页 列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("business:fbaplanorder:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<FbaPlanOrder> list = new ArrayList<FbaPlanOrder>();
        try {
            list = fbaPlanOrderService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     * @Description: 查询页 子列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("business:fbaplanorder:list")
    @GetMapping("/sonlist")
    @ResponseBody
    public AjaxResult sonlist(@RequestParam Map<String, Object> params) {
    	
        try {
            AjaxResult ajaxResult = new AjaxResult();
            Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();
            Map<String, Object> params1 = new HashMap<String, Object>();
            Map<String, Object> mapList = new HashMap<>();
            Map<String, Object> stringObjectMap = new HashMap<>();
            params.put("toolBarWidth", 0);
            if (params.get("num").equals("0")){
                params.put("moduleTable", moduleTable2);
                params.put("entity", new FbaPlanOrderDetail());
                params.put("orderby", "CodeStockLocation,t1.CommodityCode");
                stringObjectMap = gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
                mapList.put("sonList", fbaPlanOrderService.querySonList(params));

            } else if (params.get("num").equals("1")){
                params.put("moduleTable", moduleTableHJD);
                params.put("entity", new FbaShipmentDetail());
                params.put("code",params.get("code"));
                stringObjectMap = gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
                mapList.put("sonList", fbaShipmentDetailService.queryList(params));
            } else if (params.get("num").equals("2") || params.get("num").equals("3")){
                params.put("moduleTable", moduleTable_ZXDL);
                params.put("entity", new FbaBoxDetail()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
                params.put("codeBox",params.get("code"));
                params.remove("code");
                if (params.get("creationMethod").equals("手动")){
                    mapList.put("sonList", fbaBoxDetailService.queryList(params));
                } else {
                    mapList.put("sonList", fbaBoxDetailService.queryAutoList(params));
                }
                stringObjectMap = gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
//                params.put("moduleTable", moduleTable_ZXDL);
//                params.put("entity", new FbaBoxDetail()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
//                params.put("codePlanOrder",params.get("code"));
//                params.remove("code");
//                mapList.put("sonList", fbaBoxDetailService.queryList(params));
//                stringObjectMap = gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
            } else if (params.get("num").equals("4") || params.get("num").equals("5")|| params.get("num").equals("6")){
                params.put("moduleTable", moduleTable_CXXQ);
                params.put("entity", new FbaDevanningDetail());
                stringObjectMap = gridColumnsPropertyModel.queryGridColumnsPropertyModel(params);
                params1.put("moduleTable", moduleTable_ZXDL);
                params1.put("entity", new FbaBoxDetail()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
                params1.put("codeBox",params.get("code"));
                params1.put("num",3);
                params1.remove("code");
                if (params.get("creationMethod").equals("手动")){
                    mapList.put("sonList", fbaBoxDetailService.queryList2(params1));
                } else {
                    mapList.put("sonList", fbaBoxDetailService.queryAutoList(params1));
                }
            }
//            params.put("checkBox", "no");
            mapList.put("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
            mapList.put("gridColumns", stringObjectMap);
            ajaxResult = AjaxResult.success(mapList);
            return ajaxResult;
        } catch (Exception e) {
            return AjaxResult.error(this.getExceptionMessage(e));
        }
    }


    /**
     * 打开产品选择页面
     *
     * @param params
     * @return ModelAndView
     * @author DH-Xxj
     */
    @GetMapping("/select2")
    public ModelAndView selectbusinessList(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable_ACTIVE);
        params.put("entity", new ProductActive()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("toolBarWidth", 0);
        if (params.get("pagetype") != null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))
            params.put("checkBox", "yes");
        else params.put("radio", "yes");
        ModelAndView mv = this.getModelAndView();
        AjaxResult ajaxResult = new AjaxResult();
        Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();
        mv.addObject("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
        mv.addObject("ajaxResult", ajaxResult);
        mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
        mv.addObject("prefix", prefix);
        mv.addObject("moduleTable", moduleTable_ACTIVE);
        mv.addObject("pagetype", params.get("pagetype").toString());
        mv.addObject("fmoduleTable", params.get("fmoduleTable").toString());
        mv.addObject("vGsBm", params.get("vGsBm").toString());
        if (params.get("selectedObject") != null && params.get("selectedObject") != "") {
            String selectedObject = params.get("selectedObject").toString();
            mv.addObject("selectedObject", selectedObject);
        }
        mv.setViewName("system/organization/mzjobject_select");
        return mv;
    }


    /**
     * @Description: 数据导出Excel
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("business:fbaplanorder:export")
    @Log(title = "头程计划数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
        params.put("moduleTable", moduleTable);
        params.put("entity", new FbaPlanOrder());

        List<FbaPlanOrder> list = fbaPlanOrderService.queryList(params);

        params.put("getFieldAttributesType", "export");
        List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<FbaPlanOrder> util = new ExportExcelUtils<FbaPlanOrder>(moduleTable, new FbaPlanOrder());
        return util.exportExcel(list, fieldList, "头程计划数据", "export");
    }


    /**
     * @Description: 保存数据
     * @Param: infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     * @Param: infoItems 必要参数：对应实体类的json格式字符串
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:44
     */
    @RequiresPermissions(value = {"business:fbaplanorder:add", "business:fbaplanorder:edit", "business:fbaplanorder:delete"}, logical = Logical.OR)
    @Log(title = "头程计划单", businessType = BusinessType.UPDATE)
    @PostMapping("/editpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult editpost(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = fbaPlanOrderService.saveData(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }



    /**
     * @Description: 修改审核状态
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-17 14:55
     */
    @RequiresPermissions("business:fbaplanorder:updateState")
    @Log(title = "修改头程审核状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateState")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult updateState(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = fbaPlanOrderService.updateState(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }


    /**
     * @Description: 删除未审核数据
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-17 14:55
     */
    @RequiresPermissions("business:fbaplanorder:delete")
    @Log(title = "删除头程计划", businessType = BusinessType.UPDATE)
    @PostMapping("/delete")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult delete(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = fbaPlanOrderService.delete(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }



    /**
     * 打开流转页
     * @param fType 必要参数：审核类型（flow_go：流转，flow_back：退回）
     * @param infoMap 必要参数：非网格字段（包括所有显示和隐藏的字段），json格式字符串
     * @return
     * @author DH-Xxj
     */
    @RequiresPermissions("business:fbaplanorder:flow")
    @PostMapping("/flowpage")
    @ResponseBody
    public AjaxResult flowPage(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        params.put("prefix", prefix);
        return openFlowPage(params);
    }

    /**
     *@Description: 流转
     *@Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     *@Param: [params] infoItems 必要参数：对应实体类的json格式字符串（仅需 guid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 11:42
     */
    @RequiresPermissions("business:fbaplanorder:flow")
    @Log(title = "头程计划单", businessType = BusinessType.FLOWGO)
    @PostMapping("/flowgopost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowGoSave(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= fbaPlanOrderService.updateFlowGo(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     *@Description: 退回
     *@Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     *@Param: [params] 必要参数：对应实体类的json格式字符串（仅需 guid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 11:42
     */
    @RequiresPermissions("business:fbaplanorder:flow")
    @Log(title = "头程计划单", businessType = BusinessType.FLOWBACK)
    @PostMapping("/flowbackpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowBackSave(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= fbaPlanOrderService.updateFlowBack(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }


    /**
     * 查询选品库
     * @param params
     * @return
     * @author DH-Xxj
     */
    @GetMapping("/list2")
//    @RequiresPermissions("business:fbaplanorder:list2")
    @ResponseBody
    public TableDataInfo list2(@RequestParam Map<String, Object> params){
        params.put("moduleTable", planInventory);
        List<FbaProductActive> list = new ArrayList<FbaProductActive>();
        try {
            list = fbaPlanOrderService.queryFbaProductActive(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     *@Description: 查询已选择的商品
     *@Param: selectedUser ：已选中的商品编号字符串，示例：0000,1001,1002
     *@return: com.dhecp.common.core.page.TableDataInfo
     *@Author: hlf
     *@date: 2022-08-18 17:13
     */
    @GetMapping("/listselect")
    @ResponseBody
    public TableDataInfo userInfoSelectListJson(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        List<FbaProductActive> list = new ArrayList<FbaProductActive>();
        if (params.get("selectedUser") != null && params.get("selectedUser") != ""){
            String wherestrhand = "t1.guid in ('" + params.get("selectedUser").toString().replace(",", "','") + "')";
            params.put("wherestrhand", wherestrhand);
            try{
                list = fbaPlanOrderService.queryFbaProductActive(params);
            }catch(Exception e){
                return getDataTable(this.getExceptionMessage(e).toString());
            }
        }else{
            return getDataTable("请传入已选中的商品编码字符串（selectedUser），取值示例：0000,1001,1002");
        }
        return getDataTable(list);
    }

}